(function() {
    var x = ["#ef5b9c", "#2a5caa", "#f47920", "#5c7a29", "#006c54", "#694d9f"];
    console.log(App.get("$Cache.action.moduleCount"));
    Path.on("/__basename__.html", function(_current_location) {
        var qs = _current_location.query;
        var section_id = qs.get("section_id");
        App.set("$Cache.action._current_section_id", section_id);
        var article_id = qs.get("article_id");
        var news_url = section_id ? public_api.news.get.list_by_section_id + section_id : public_api.news.get.list_all;
        // 获取文章板块
        coAjax.get(public_api.section.get.list_all, function(result) {
            for (var i = 0; i < x.length; i++) {
                // console.log(result[i])
                if (typeof result[i] == "object") {
                    // 随即变换标签背景色
                    result[i].bg = x.sort(function() {
                        return Math.random() - 0.3;
                    })[1];
                };
            };
            App.set("$Cache.action.section_list", result);
            // console.log(result);
        });
        // 获取文章列表
        coAjax.get(news_url, function() {}).then(function(list) {
            if (!list.info.data.length) {
                return;
            };
            App.set("$Cache.action.article_list", list.info);
            article_id = article_id ? article_id : list.info.data[0]._id;
            App.set("$Cache.action._current_article_id", article_id);
            // 根据id获取文章内容
            coAjax.get(public_api.news.get.detail_by_id + article_id, function(article) {
                try {
                    article.html = decodeURIComponent(article.html);
                } catch (e) {
                    console.log(e);
                    article.html = article.html;
                };
                App.set("$Cache.action.article.detail", article);
                console.log(article);
            });
        });
    });
    // 手机显示文章列表
    App.set("$Event.action.mobile.show_list", function() {
        App.model.toggle("$Cache.action.mobile.show_list");
    })
}());